﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XCommon.Types;
using XWeb.Code;
using XModel;

namespace XWeb
{
    public partial class DataForm : Code.Page.UIBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void GetGroupNav()
        {
            // 客户端返回的tbGroups数据条数数量
            int customerTypeCount = 0;
            int.TryParse(this.GetValue(XConst.S_KEY_GROUPTYPECOUNT), out customerTypeCount);
            XCommon.LogHelper.CreateDebugLog("customertypecount = " + customerTypeCount);
            string strWrite;
            if (customerTypeCount != XCacheManager.It.TbGroupsCount)
            {
                strWrite = XDALManager.It.GettbGroups();
            }
            else
            {
                strWrite = XNormalJson.It.NotUpdatetbGroups;
            }
            this.WriteOut(strWrite, HTMLContentType.JSON);
        }

        public void GetGroupDataList()
        {
            int groupid = 0;
            byte pageindex = 0;
            int.TryParse(this.GetValue(Code.XConst.S_KEY_GROUPID), out groupid);
            byte.TryParse(this.GetValue(Code.XConst.S_KEY_PAGEINDEX), out pageindex);
            string strWrite = XDALManager.It.GetGroupListData(groupid, pageindex);
            this.WriteOut(strWrite, HTMLContentType.JSON);
        }

        public void InsertUser()
        {
            bool bRet = XDAL.tbUser.It.Insert(this.PhoneKey);
            this.WriteOut(bRet.ToString(), HTMLContentType.JSON);
        }

        public void GetToDayList()
        {

        }

        public void GetPhotoItem()
        {
            ushort itemid = 0;
            ushort.TryParse(this.GetValue(Code.XConst.S_KET_PHOTOITEMID), out itemid);
            string strJson = XDALManager.It.GetPhotoItem(itemid);
            this.WriteOut(strJson, HTMLContentType.JSON);
        }

        /// <summary>
        /// 获取服务端更新列表
        /// 上传客户端有多少条数据.
        /// </summary>
        public void GetImageItem()
        {
            int nCount = 0;
            int.TryParse(this.GetValue(Code.XConst.S_KEY_COUNT), out nCount);
            List<EImageItem> ps = XDAL.tbImageItem.It.Get(nCount);
            if (ps == null || ps.Count <= 0) return;
            this.WriteOut(XCommon.LitJson.JsonMapper.ToJson(ps), HTMLContentType.JSON);
        }
    }
}